<?php if(isset($_SESSION['user']['user_id']) && $_SESSION['user']['user_id']!=""){?>
<div class="col-md-8">
<div class="main-content" id="main-content">
	<div class="sub-content">
		<div class="top-header page-header clearfix">
			<h1>Sell Offer Info</h1>
		</div>
		<div class="top-links">
			<ul class="form-progress-bar">
				<li class="active-menu step-no"><a href="<? echo $this->Url('products')?>/add-product"><span>1</span></a></li>
				<li class="indicator"><span></span></li>
				<li class="step-no"><span>2</span></li>
				<li class="indicator"><span></span></li>
				<li class="step-no"><span>3</span></li>
			</ul>
		</div>
		<div class="col-md-12">
			<form id="forms" method="post" class="form-horizontal" role="form">
				
					<? if(isset($_SESSION['user']['user_type']) && $_SESSION['user']['user_type']=="superadmin"){?>
					<div class="form-group" id="formsListAdmin">
								<label class="control-label col-sm-3">Admin</label>
								<div class="col-sm-9">
								<div class="select_6">	
									<select id="admindropdown" name="admindropdown" onchange="getUsers()" class="form-control">
										<? if(count($getalladmins)>0){foreach($getalladmins as $admins){?>
										<?php if(isset($_SESSION['products']['admin_user_id'])){if($_SESSION['products']['admin_user_id']==$admins->user_id){?>
											<option value="<? echo $admins->user_id.'/'.$admins->company_name;?>" selected="selected"><? echo $admins->company_name;?></option>
										<?}} else if($this->productsDeatils->parent_user_id==$admins->user_id){?>
											<option value="<? echo $admins->user_id.'/'.$admins->company_name;?>" selected="selected"><? echo $admins->company_name;?></option>
										<?}else{?>
										<option value="<? echo $admins->user_id.'/'.$admins->company_name;?>"><? echo $admins->company_name;?></option>
										<?}}}?>
									</select>
								</div>
								</div>
					</div><span style="color:red" id="erroradmin"></span>
					<?} if($_SESSION['user']['user_type']!="user"){?>
					<div class="form-group" id="formsListUser">
						<label class="control-label col-sm-3">User</label>
						<div class="col-sm-9">
						<div class="select_6">
							<select id="userdropdown" name="userdropdown" onchange="getCurrency(this.value)" class="form-control">
								<option value=''>Select a user</option>
							</select>
						</div></div>	
					</div><span style="color:red" id="erroruser"></span>
					<?} else if($_SESSION['user']['user_type']=="user"){?>
					<div class="form-group" id="hiddentbox">
						<label class="control-label col-sm-3">User Name</label>
						<div class="col-sm-9">
						<input type="text" name="usertextbox" id="usertextbox" readonly="readonly" class="form-control" value="<? if(isset($_SESSION['user']['username'])){ echo $_SESSION['user']['username'];} ?>">
						<input type="hidden" name="userdropdown" id="userdropdown" value="<? if(isset($_SESSION['user']['user_id'])){ echo $_SESSION['user']['user_id'].'/'.$_SESSION['user']['username'];} ?>">
					</div></div>
					<?}?>
					<input type="hidden" value="<? if(isset($this->productsDeatils->user_id) && $this->productsDeatils->user_id!=""){ echo $this->productsDeatils->user_id;}?>" id="hidajx_user_id" name="hidajx_user_id">
					<input type="hidden" value="<? if(isset($this->productsDeatils->category_id) && $this->productsDeatils->category_id!=""){ echo $this->productsDeatils->category_id;}?>" id="hidajx_cat_id" name="hidajx_cat_id">
					<div class="form-group">
						<label class="control-label col-sm-3">Brand/Grade No</label>
						<div class="col-sm-9">
						<? if(isset($_SESSION['products']['brand']) && $_SESSION['products']['brand']!=""){?>
							<input type="text" value="<? echo $_SESSION['products']['brand'];?>" id="brand" name="brand" class="form-control" placeholder="eg Acranol 290D" />
						<?}else if(isset($this->productsDeatils->brandcode) && $this->productsDeatils->brandcode!=""){?>
							<input type="text" value="<?php echo $this->productsDeatils->brandcode;?>" id="brand" class="form-control" name="brand" placeholder="eg Acranol 290D" />
						<?}else{?>
							<input type="text" value="" id="brand" name="brand" class="form-control" placeholder="eg Acranol 290D" />
						<?}?></div>
					</div><span style="color:red" id="errorbrand"></span>
					<div class="form-group">
						<label class="control-label col-sm-3">Generic Name</label>
						<div class="col-sm-9">
						<? if(isset($_SESSION['products']['generic']) && $_SESSION['products']['generic']!=""){?>
							<input type="text"  value="<?php echo $_SESSION['products']['generic'];?>" class="form-control" id="generic" name="generic" placeholder="eg Styrene Acrylic Emulsion" />
						<?}else if(isset($this->productsDeatils->genericname) && $this->productsDeatils->genericname!=""){?>
							<input type="text"  value="<?php echo $this->productsDeatils->genericname;?>" class="form-control" id="generic" name="generic" placeholder="eg Styrene Acrylic Emulsion" />
						<?}else{?>
							<input type="text"  value="" id="generic" name="generic" class="form-control" placeholder="eg Styrene Acrylic Emulsion" />
						<?}?></div>
					</div><span style="color:red" id="errorgname"></span>
					<div class="form-group">
						<label class="control-label col-sm-3">Fuction</label>
						<div class="col-sm-9">
						<? if(isset($_SESSION['products']['fuction']) && $_SESSION['products']['fuction']!=""){?>
							<input type="text"  value="<?php  echo $_SESSION['products']['fuction'];?>" id="fuction" class="form-control" name="fuction" placeholder="eg Binder, Defoamer, Biocide" />
						<?}else if(isset($this->productsDeatils->fuction) && $this->productsDeatils->fuction!=""){?>
							<input type="text"  value="<?php  echo $this->productsDeatils->fuction;?>" id="fuction" class="form-control" name="fuction" placeholder="eg Binder, Defoamer, Biocide" />
						<?}else{?>
							<input type="text"  value="" id="fuction" name="fuction" class="form-control" placeholder="eg Binder, Defoamer, Biocide" />
						<?}?></div>
					</div><span style="color:red" id="errorfunction"></span>
					<div class="form-group">
						<label class="control-label col-sm-3">Manufacturer</label>
						<div class="col-sm-9">
						<? if(isset($_SESSION['products']['manufacture']) && $_SESSION['products']['manufacture']!=""){?>
							<input type="text" value="<?php echo $_SESSION['products']['manufacture'];?>" class="form-control" id="manufacture" name="manufacture" placeholder="eg BASF" />
						<?}else if(isset($this->productsDeatils->manufacturer) && $this->productsDeatils->manufacturer!=""){?>
							<input type="text" value="<?php echo $this->productsDeatils->manufacturer;?>" class="form-control" id="manufacture" name="manufacture" placeholder="eg BASF" />
						<?}else{?>
							<input type="text" value="" id="manufacture" name="manufacture" class="form-control" placeholder="eg BASF" />
						<?}?></div>
					</div><span style="color:red" id="errormanufacture"></span>
					<div class="form-group">
						<label class="control-label col-sm-3">Origin</label>
						<div class="col-sm-9">
						<div class="select_6">
							<select id="origin" name="origin" class="form-control">
								<option value="">-Select a Origin</option>	
								<?php if(isset($getCountries) && count($getCountries)>0){foreach($getCountries as $countries){ 								
								if($_SESSION['products']['origin']==$countries->country_id){?>
									<option value="<? echo $countries->country_id.'/'.$countries->nicename;?>" selected="selected"><? echo $countries->nicename;?></option> 
								<?}else if($this->productsDeatils->origin_country==$countries->country_id){?>
									<option value="<? echo $countries->country_id.'/'.$countries->nicename;?>" selected="selected"><? echo $countries->nicename;?></option> 
								<?}else{?>
									<option value="<? echo $countries->country_id.'/'.$countries->nicename;?>"><? echo $countries->nicename;?></option> 
								<?}}}?>
							</select>
						</div></div>
					</div><span style="color:red" id="errororigin"></span>
					<input type="hidden" name="hid_region_id" value="<? if(isset($this->productsDeatils->origin_country)){ echo $this->productsDeatils->origin_country;}?>" id="hid_region_id"/>
					<div class="form-group">
						<label class="control-label col-sm-3">Categories</label>
						<div class="col-sm-9">
						<div class="select_6">
							<select id="category_id" name="category_id" class="form-control">
								<option value="">-Select Category</option>
								<? if(count($this->getallcategories)>0){foreach($this->getallcategories as $categories){?>
								<?php if($_SESSION['products']['category_id']==$categories->category_id){?>
									<option value="<? echo $categories->category_id.'/'.$categories->category_name;?>" selected="selected"><? echo $categories->category_name;?></option> 
								<?}else if($this->productsDeatils->category_id==$categories->category_id){?>
									<option value="<? echo $categories->category_id.'/'.$categories->category_name;?>" selected="selected"><? echo $categories->category_name;?></option> 
								<?} else{?>
									<option value="<? echo $categories->category_id.'/'.$categories->category_name;?>"><? echo $categories->category_name;?></option> 
								<?}}}?>								    
							</select>
						</div></div>
					</div><span style="color:red" id="errorcategory"></span>
					<input type="hidden" id="hid_product_id" name="hid_product_id" value="<? if(isset($_GET['product_id'])){ echo $_GET['product_id'];}?>"/>
					<div class="form-group">
					<div class="col-sm-3">&nbsp;</div>
						<div class="col-sm-9">
						<a  href="javascript:void(0)" class="btn btn-danger" role="button" onclick="return submitValues()">Continue</a></div>
					</div>
				
			</form>
		</div>
	 </div>
</div> </div>
<script>
$(function(){
	<? if(isset($_SESSION['user']['user_type'])){if($_SESSION['user']['user_type']=='superadmin'){?>
		getUsers();
	<?}else if($_SESSION['user']['user_type']=='admin'){?>
		var adminUserId=<? echo $_SESSION['user']['user_id'];?>;
		adminUser(adminUserId);
	<?}}?>	
	});	
	function getUsers(){
		<?php if(isset($_SESSION['products']['admin_user_id']) && $_SESSION['products']['admin_user_id']!=""){?>
			var user_id=$('#admindropdown').val();			
		<?php }else{?>
			var user_id=$('#admindropdown').val();	
		<?php }?>
		if($("#hidajx_user_id").val()!=""){
			var hid_user_id=$("#hidajx_user_id").val();
		}else{
			var hid_user_id='';
		}
		var check='check';
		$.ajax
		({
		type: "GET",
		url:   	BASE_PATH+'/products/product-ajax?user_id='+ user_id +'&user_user_id='+ hid_user_id +'&check='+check,
		success: function(data)
		{
			if(data.getadminUsers==''){
				alert('There are no users under selected admin');
				$("#userdropdown").html('<option value="">Select user</option>');
			}else{
				$("#userdropdown").html(data.getadminUsers );
				var user_id=$("#userdropdown").val();
				getCurrency(user_id);
			}
		}
		});	
	}
	function adminUser(adminUserId){
		var adminUserId=<? echo $_SESSION['user']['user_id'];?>;
		if($("#hidajx_user_id").val()!=""){
			var hid_user_id=$("#hidajx_user_id").val();
		}else{
			var hid_user_id='';
		}
		$.ajax({
			type: "POST",
			url:   	BASE_PATH+'/products/admin-users-ajax',
			data: {adminUserId:adminUserId,user_user_id:hid_user_id},
			success: function(data){
				$("#userdropdown").html(data.getadminUsers );
				var user_id=$("#userdropdown").val();
				getCurrency(user_id);
			}
		});		
	}
	function submitValues(){
	    var flag=true;	
		var letters = /^[a-zA-Z ]*$/; 
		var numbers = /^[0-9]+$/;
		var admindrop =$('#admindropdown').val();
		var userdrop =$('#userdropdown').val();
		var brand=$('#brand').val();
		var generic=$('#generic').val();
		var fuction=$('#fuction').val();
		var manufacture=$('#manufacture').val();
		var origin=$('#origin').val();
		var category=$('#category_id').val();
		if(admindrop==""){
			$('#erroradmin').html('*Admin is required');	
			flag=false;
		}else{
			$('#erroradmin').html('');
		}
		if(userdrop==""){
			$('#erroruser').html('*User is required');	
			flag=false;
		}else{
			$('#erroruser').html('');
		}
		if(brand==""){
			$('#errorbrand').html('*Brand/grade number is required');	
			flag=false;
		}else{
			$('#errorbrand').html('');
		}
		
		if(generic==""){
			$('#errorgname').html('*Generic name is required');	
			flag=false;
		}else{
			$('#errorgname').html('');
		}
		if(fuction==""){
			$('#errorfunction').html('*Function is required');
			flag=false;
		}else{
			 $('#errorfunction').html('');
		}
		if(manufacture==""){
			$('#errormanufacture').html('*Manufacturer is required');
			flag=false;
		}else{
			 $('#errormanufacture').html('');
		}
        if(origin==""){
			$('#errororigin').html('*Origin is required');
			flag=false;
		}else{
			 $('#errororigin').html('');
		}
		if(category==""){
			$('#errorcategory').html('*Category is required');
			flag=false;
		}else{
			 $('#errorcategory').html('');
		}
		if(flag==false){ 
			return false;
		}else{		
			$("#forms").submit();
		}
	}
	
		function changePrice(){
			var country_id=$('#origin').val();
			$.ajax({
				type:	'POST',
				url:   	BASE_PATH+'/products/add-product-next',
				data:	{country_id:country_id,changeprice:'changeprice'},
				success: function(data){}
			});
		}
	$( document ).ready(function() {
		if($("#userdropdown").val()==''){
			var user_id=null;
		}else{
			var user_id=$("#userdropdown").val();
		}		
		getCurrency(user_id);
	});
	function getCurrency(user_id){
		var user_category_id=$("#hidajx_cat_id").val();
		var user_region_id=$("#hid_region_id").val();
		$.ajax({
			type:	'POST',
			url:   	BASE_PATH+'/products/add-product-next',
			data:	{user_id:user_id,changeprice:'changeprice'},
			success: function(data){
				var user_id=$("#userdropdown").val();
				$.ajax({
					type: "POST",
					url:   	BASE_PATH+'/products/get-categories-ajax',
					data: {user_id:user_id,user_category_id:user_category_id},
					success: function(data){
						$("#category_id").html(data.categories );					
					}
				});		
			}
		});
	}
</script>
<?php }else{?>
<script>
	window.location='<? echo $this->Url('home')?>';
</script>
<?php }?>